
import pickle as pickle
import numpy as np

with open('moistheight.pickle','rb') as handle:
    dat = pickle.load(handle)

with open('resultgrid-10ppm-height.pickle','rb') as handle:
    result = pickle.load(handle)
    
krain = np.zeros(((len(dat['fv']),len(dat['Ts']))))
edd = 10.0 # m2/s

p = {}

for ifv in range(0,len(dat['fv'])):
    for iTs in range(0,len(dat['Ts'])):

        p['Hsca'] = dat['moistheight'][ifv,iTs]*1e3 # km to m                                                                                                        
        if p['Hsca'] == 0:
            continue
        p['tau_eddy'] = p['Hsca']**2/(2*edd)
        krain[ifv,iTs] = 1/(p['tau_eddy']/((10e-6/(result['result'][ifv,iTs,0]))-1))
    
with open('tau_rain.pickle','wb') as handle:
    pickle.dump(krain,handle)

outfile = open('tau_rain.txt','w')
for ifv in range(0,len(dat['fv'])):
    for iTs in range(0,len(dat['Ts'])):
        outfile.write(dat['fv'][ifv]+'    '+dat['Ts'][iTs].ljust(10)+'%.3e'%(krain[ifv,iTs])+'\n')
